package com.nakamachizu.base;

import org.slim3.controller.Controller;
import org.slim3.controller.Navigation;

import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;
import com.nakamachizu.util.ForwardUtil;

public abstract class LoginBaseController extends Controller{

    protected abstract Navigation execute() throws Exception;
    
    @Override
    protected Navigation run() throws Exception{
        requestScope("requestURI", request.getRequestURI());
        
        if(isLogin()){
            return execute();
        }else{
            return forward(ForwardUtil.forwardJsp("login.jsp"));
        }
    }
    
    protected boolean isLogin() {
        
        UserService userService = UserServiceFactory.getUserService();
        User user = userService.getCurrentUser();
        
        if(user != null){
            return true;
        }else{
            return false;
        }
    }
}
